def count_picks(cards)
  cur_idx = 0
  result = 1
  cards.sort!
  (1..cards.size).each do |i| #i denotes i-th pickup turn. We will count possibilities for i-th pickup
    cur_idx += 1 while (cur_idx < cards.size and cards[cur_idx] < i) # and bound check for cur_idx
    #so for i-th pickup we have choices:
    choices = cur_idx - (i-1)
    #p "choices = #{choices}, cur_idx = #{cur_idx}"
    return '0' if choices <= 0
    result *= choices
    result %= 1000000007 if result > 1000000007
  end
  return result.to_s
end

def from_stdin
  tests = Array.new
  num_tests = gets.to_i
  num_tests.times do
    num_cards = gets.to_i
    inp_cards = gets.split.map{|x| x.to_i}
    tests << inp_cards
  end
  
  num_tests.times do |i|
    puts count_picks(tests.shift)
  end 
end

from_stdin


def from_file filename
  tests = Array.new
  file = File.open(filename)
  num_tests = file.gets.to_i
  num_tests.times do
    num_cards = file.gets.to_i
    inp_cards = file.gets.split.map{|x| x.to_i}
    tests << inp_cards
  end
  
  
 
  outfile = File.open(filename.gsub(/(input)(\d\d).txt$/, 'output\2.txt')).each_line do |line|
    answer_str = line.gsub(/\n/,'')
    result_str = count_picks(tests.shift)
    if answer_str != result_str
      puts "Does not match: Answer = \n#{answer_str} vs Result = \n#{result_str}"
      return
    end
  end
  p "SUCCESS with file #{filename.match(/(input\d\d).txt$/)[0]}"
end

file_num = "00"
0.times do
  from_file 'C:\Users\kirill\Documents\interview_street\Picking-Cards_testcases\input' + file_num + '.txt'
  file_num.succ!
end


